<template>
    <el-dialog v-model="companyDataStore.createDialogVisible" width="580" :show-close="false" :z-index="9">
        <template #header>
            <div class="dialog-header">
                <h4>创建企业</h4>
                <!-- <div class="tip">
                    <el-icon :size="18">
                        <Warning />
                    </el-icon>
                    <span>创建企业并实名成功后，将生成对应企业名称的公章</span>
                </div> -->
            </div>
        </template>
        <div class="dialog-content">
            <div class="label">请输入您的企业名称，并确保与营业执照上的企业名称一致</div>
            <el-input v-model="companyName" placeholder="请输入企业名称" />
        </div>
        <template #footer>
            <div class="dialog-foot">
                <el-button @click="companyDataStore.createDialogVisible = false">取消</el-button>
                <el-button type="primary" :loading="loading" @click="handleCreate">
                    确定
                </el-button>
            </div>
        </template>
    </el-dialog>
</template>
<script lang="ts" setup>
import { ref, computed } from 'vue'
import { CreateCompany } from '@/api/enterprise'
import { ElMessage, ElMessageBox } from 'element-plus'
import { useCompanyDataStore } from '@/store/companys'

const companyDataStore = useCompanyDataStore()

const loading = ref(false)
const companyName = ref('')

const handleCreate = () => {
    if (!companyName.value.trim()) {
        return ElMessage.error('企业名称不能为空')
    }
    loading.value = true
    CreateCompany({
        name: companyName.value.trim()
    }).then(res => {
        loading.value = false
        ElMessage.success('创建成功')
        companyName.value = ''
        companyDataStore.createDialogVisible = false
        companyDataStore.init()
    }).catch(() => {
        loading.value = false
    })
}

</script>
<style scoped lang="scss">
.dialog-header {
    display: flex;
    align-items: center;
    padding: 10px;

    h4 {
        font-size: 18px;
        color: #333;
        font-weight: normal;
    }

    .tip {
        font-size: 16px;
        color: #999;
        background-color: #f3f8fb;
        display: flex;
        align-items: center;
        padding: 3px 5px;
        border-radius: 5px;
        margin-left: 10px;

        span {
            margin-left: 5px;
        }
    }
}

.dialog-content {
    padding: 0 10px;

    .label {
        font-size: 16px;
        color: #666;
        margin-bottom: 20px;
    }
}

.dialog-foot {
    padding: 10px;
}
</style>